export default {
	computed: {
		$userInfo() {
			return this.$store.state.app.userInfo
		},
		$income() {
			return [{
				value: 1,
				label: "10万-20万"
			}, {
				value: 2,
				label: "20万-30万"
			}, {
				value: 3,
				label: "30万-50万"
			}, {
				value: 4,
				label: "50万-100万"
			}, {
				value: 5,
				label: "100万以上"
			}]
		},
		$statusMap() {
			return {
				1: {
					text: '录入',
					class: 'status-1'
				},
				2: {
					text: '分配',
					class: 'status-2'
				},
				3: {
					text: '跟进',
					class: 'status-3'
				},
				4: {
					text: '解绑',
					class: 'status-41'
				},
				41: {
					text: '退回公共池',
					class: 'status-41'
				},
				14: {
					text: '认购',
					class: 'status-14'
				},
				15: {
					text: '签约',
					class: 'status-15'
				}
			}
		},
		$ages() {
			return [{
					"text": "20岁以下",
					"value": 1
				},
				{
					"text": "21-25",
					"value": 2
				},
				{
					"text": "25-30",
					"value": 3
				},
				{
					"text": "31-35",
					"value": 4
				},
				{
					"text": "35-40",
					"value": 5
				},
				{
					"text": "40-45",
					"value": 6
				},
				{
					"text": "55-60",
					"value": 7
				},
				{
					"text": "51-55",
					"value": 8
				},
				{
					"text": "60岁以上",
					"value": 9
				}
			]
		},
		$familyList() {
			return [{
					"text": "单身",
					"value": 1
				},
				{
					"text": "二人世界",
					"value": 2
				},
				{
					"text": "三口之家",
					"value": 3
				},
				{
					"text": "6四口之家",
					"value": 4
				}, {
					"text": "6五口及以上",
					"value": 5
				}
			]
		},
		$useTypeList() {
			return [{
					"text": "投资",
					"value": 1
				},
				{
					"text": "自住",
					"value": 2
				},
				{
					"text": "投资+自住",
					"value": 3
				}
			]
		},
		$liveList() {
			return [{
					"text": "渝中",
					"value": 1
				},
				{
					"text": "渝北",
					"value": 2
				},
				{
					"text": "江北",
					"value": 3
				},
				{
					"text": "沙坪坝",
					"value": 4
				}, {
					"text": "南岸",
					"value": 5
				}, {
					"text": "大渡口",
					"value": 6
				}, {
					"text": "九龙坡",
					"value": 11
				},{
					"text": "巴南",
					"value": 7
				}, {
					"text": "区县",
					"value": 8
				},
				{
					"text": "新桥",
					"value": 9
				},
				{
					"text": "外地",
					"value": 10
				}

			]
		},
		$paymentOptions() {
			return [{
					text: '全款',
					value: '1'
				},
				{
					text: '商业贷款',
					value: '2'
				},
				{
					text: '公积金贷款',
					value: '3'
				},
				{
					text: '组合贷款',
					value: '4'
				}
			]
		},
		$budgetList() {
			return [{
					"text": "70以下",
					"value": "70"
				},
				{
					"text": "70-90",
					"value": "80"
				},
				{
					"text": "90-110",
					"value": "100"
				},
				{
					"text": "110-130",
					"value": "120"
				},
				{
					"text": "130-150",
					"value": "140"
				},
				{
					"text": "150-170",
					"value": "160"
				},
				{
					"text": "170以上",
					"value": "180"
				}
			]
		},

		$productList() {
			return [{
					text: '高层',
					value: '1'
				},
				{
					text: '洋房',
					value: '2'
				},
				{
					text: '别墅',
					value: '3'
				},
				{
					text: '商业',
					value: '4'
				},
			]
		},
		$areas() {
			return [{
					"text": "50以下",
					"value": 50
				},
				{
					"text": "60",
					"value": 60
				},
				{
					"text": "70",
					"value": 70
				},
				{
					"text": "80",
					"value": 80
				},
				{
					"text": "90",
					"value": 90
				},
				{
					"text": "100",
					"value": 100
				},
				{
					"text": "110",
					"value": 110
				},
				{
					"text": "120",
					"value": 120
				},
				{
					"text": "130",
					"value": 130
				},
				{
					"text": "140",
					"value": 140
				},
				{
					"text": "150以上",
					"value": 150
				}
			]
		},
		// 50以下，60，70，80，90，100，110，120，130，140，150以上
		$sourceType() {
			return [{
					"text": "自然到访",
					"value": 1
				},
				{
					"text": "项目周边广告",
					"value": 2
				},
				{
					"text": "电梯广告",
					"value": 3
				},
				{
					"text": "中介（贝壳）",
					"value": 4
				},
				{
					"text": "中介（到家了）",
					"value": 5
				},
				{
					"text": "全民经纪人",
					"value": 6
				},
				{
					"text": "小红书",
					"value": 7
				},
				{
					"text": "抖音",
					"value": 8
				},
				{
					"text": "公众号",
					"value": 9
				},
				{
					"text": "微信朋友圈",
					"value": 10
				},
				{
					"text": "老业主介绍",
					"value": 11
				},
				{
					"text": "电话约访",
					"value": 12
				}
			]
		},
		$houseTypes() {
			return [{
					label: '一房',
					value: '1'
				},
				{
					label: '两房',
					value: '2'
				},
				{
					label: '2/3房',
					value: '5'
				},
				{
					label: '三房',
					value: '3'
				},
				{
					label: '四房',
					value: '4'
				},
				{
					label: '3/4房',
					value: '6'
				},
			]
		},
		$wuList() {
					return [{
							text: '商业',
							value: 1
						},
						{
							text: '住宅',
							value: 2
						},
						{
							text: '商业/住宅',
							value: 3
						}
					]
				},
				$buildings() {
					return [{
							text: '5幢',
							value: 5
						},
						{
							text: '7幢',
							value: 7
						},
						{
							text: '5幢/7幢',
							value: 10
						},
						{
							text: '其它',
							value: 20
						}
					]
				},
				$floors(){
					return [{
							text: '低',
							value: 1
						},
						{
							text: '中低',
							value: 2
						},
						{
							text: '中间',
							value: 3
						},
						{
							text: '中高',
							value: 4
						},
						{
							text: '高',
							value: 5
						}]
				},
				$houseArrow() {
					return [{
							text: '北',
							value: 1
						},
						{
							text: '东',
							value: 2
						},
						{
							text: '南',
							value: 3
						},
						{
							text: '西',
							value: 4
						}
					]
				},
				$priceList() {
					return [{
							text: '6000以下',
							value: 1
						},
						{
							text: '7000',
							value: 2
						},
						{
							text: '8000',
							value: 3
						},
						{
							text: '9000',
							value: 4
						},
						{
							text: '1万',
							value: 5
						},
						{
							text: '1.1万',
							value: 6
						},
						{
							text: '1.2万',
							value: 7
						},
						{
							text: '1.2万以上',
							value: 8
						}
					]
				},
				$badList() {
					return [{
							text: '单价',
							value: 1
						},
						{
							text: '总价',
							value: 2
						},
						{
							text: '户型',
							value: 3
						},
						{
							text: '面积',
							value: 4
						},
						{
							text: '楼层',
							value: 5
						},
						{
							text: '朝向',
							value: 6
						},
						{
							text: '地段',
							value: 7
						},
						{
							text: '小区环境',
							value: 8
						},
						{
							text: '周边环境',
							value: 9
						},
						{
							text: '物业服务',
							value: 10
						},
						{
							text: '价值投资',
							value: 11
						},
						{
							text: '资金',
							value: 12
						},
						{
							text: '决策人',
							value: 13
						}
					]
				}
	
	},
	methods: {
		$getStatusText(status) {
			return this.$statusMap[status]?.text || '未知状态'
		},
		$getStatusClass(status) {
			return this.$statusMap[status]?.class || 'status-unknown'
		},
		$formatNumber(num, options = {}) {
			if (num === null || num === undefined) return '';

			const {
				minimumFractionDigits = 0, maximumFractionDigits = 2
			} = options;

			// 简单实现千分位分隔
			let parts = Number(num).toFixed(maximumFractionDigits).split('.');
			parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');

			return parts.join('.');
		},
		$getTodayTimeRange() {
			const now = new Date();
			const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
			const endOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);

			return {
				startTime: startOfDay.getTime(), // 转换为时间戳
				endTime: endOfDay.getTime() // 转换为时间戳
			};
		},
		$getCustomType(type) {

			// "enumDescription": {
			// 	"1": "自然到访",
			// 	"2": "中介推荐",
			// 	"3": "老客户推荐",
			// 	"4": "线上渠道"
			// }
			let res = ' '
			switch (type) {
				case 1:
					res = '自然到访'
					break;
				case 2:
					res = '中介推荐'
					break;
				case 3:
					res = '老客户推荐'
					break;
				default:
					res = '其它渠道'
					break;
			}
			return res
		},
		$getLevel(level) {
			let res = ''
			switch (level) {
				case 1:
					res = 'A类'
					break;
				case 2:
					res = 'B类'
					break;
				case 3:
					res = 'C类'
					break;
				case 4:
					res = 'D类'
					break;
				default:
					res = 'E类'
					break;
			}
			return res
		},
		// 角色1管理员  2买家 3销售人员 4中介  5个人中介 6前台"
		$getRole(role) {
			let res = ''
			switch (role) {
				case 1, 0:
					res = "超级管理员"
					break;
				case 2:
					res = "买家";
					break;
				case 3:
					res = '高级置业顾问'
					break;
				case 4:
					res = "置业中介"
					break;
				case 5:
					res = "置业中介"
					break;
				case 6:
					res = "前台"
					break;
				default:
					break;
			}
			return res;
		},
		$formatPrice(price) {
			if (!price) return '￥0';
			if (price >= 10000) {
				return `￥${(price / 10000).toFixed(1)}万`;
			}
			return `￥${price.toLocaleString()}`;
		},
		$simpleToast(title, position = 'bottom', duration = 2000) {
			uni.showToast({
				title: title,
				icon: 'none',
				position: position,
				duration: duration
			})
		},
		$showLoading(title = '请稍候', mask = true) {
			uni.showLoading({
				title: title,
				mask: mask
			})
		},
		$hideLoading() {
			uni.hideLoading()
		},
		getDateTimeStamp(dateStr) {
			return Date.parse(dateStr.replace(/-/gi, "/"));
		},
		$getPageDom(dom) {
			const query = uni.createSelectorQuery().in(this);
			let res = null
			query.select(dom).boundingClientRect(data => {
				res = data
			}).exec();
			return res
		},
		$back(num = 1, type = 'pop-out', time = 200) {
			uni.hideKeyboard()
			setTimeout(() => {
				uni.navigateBack({
					delta: num,
					animationType: type,
					animationDuration: time
				})
			}, 500)
		},
		$calcIdHeight(dom, padd = 0) {
			return new Promise((resolve, reject) => {
				this.$nextTick(() => {
					uni.getSystemInfo({
						success: (resu) => {
							const query = uni.createSelectorQuery()
							query.select(dom).boundingClientRect()
							query.exec(res => {
								var height = resu.windowHeight - res[0].top - padd
								resolve(height)
							})
						},
						fail: (res) => {
							reject(res)
						}
					})
				})
			})

		},
		$cloudOBjAjax(name, method, data) {
			const cloudObj = uniCloud.importObject(name)
			let userInfo = this.$userInfo
			return new Promise((resolve, reject) => {
				console.log('cloudObj', cloudObj, name)
				if (!cloudObj) {
					reject({
						code: 404,
						errMsg: "没有找到接口"
					})
				}
				cloudObj[method](data, userInfo).then(res => {

					if (res.resultCode !== 0) {
						return reject({
							code: 500,
							errMsg: res.errorMsg || res.message
						})
					}
					resolve(res.data)

				}).catch(err => {
					reject({
						code: 500,
						errMsg: err
					})
				})
			})
		},
		$getDate(data) {
			const date = new Date(data);
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();

			month = month > 9 ? month : '0' + month;
			day = day > 9 ? day : '0' + day;
			return `${year}-${month}-${day}`;
		},
		$formatPhone(phone) {
			if (!phone) return ''
			phone = phone + ''
			return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
		},
		$initTableHeight() {
			const that = this;
			this.$nextTick(function() {
				that.tableHeight = window.innerHeight - that.$refs.tableRef.$el.getBoundingClientRect().top -
					60;
			});
		},
		$formatTime(timestamp) {
			if (!timestamp) return '';
			const date = new Date(timestamp);
			return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
		},
		$formatYear(timestamp) {
			if (!timestamp) return '';
			const date = new Date(timestamp);
			return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
		}
	}
}